package com.sskj.mine.asset;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.util.CommonUtil;
import com.sskj.mine.asset.data.BeanEos;
import com.sskj.mine.asset.data.RechargeBean;
import com.sskj.mine.bean.ReWithCoinBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.util.MapToJsonUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;


/**
 * @author Hey
 * Create at  2019/05/03
 */
class RechargePresenter extends BasePresenter<RechargeActivity> {


    /**
     * 币充值页面
     *
     * @return
     */
    public void recharge(String type, String code) {
        httpService.recharge(type, code).execute(new JsonCallBack<HttpData<RechargeBean>>(this) {
            @Override
            public void onSuccess(Response<HttpData<RechargeBean>> response) {
                HttpData<RechargeBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.updateUI(httpData.getData());
                }
            }
        });
    }


    public void getType() {
        httpService.withdrawList()
                .execute(new JsonCallBack<HttpData<List<ReWithCoinBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<List<ReWithCoinBean>>> response) {
                        HttpData<List<ReWithCoinBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateType(httpData.getData());
                        }
                    }
                });
    }


    public void checkEosAccount() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "EOS");
        RequestBody body = MapToJsonUtils.mapToJson(map);
        OkGo.<HttpData<BeanEos>>post(HttpConfig.BASE_URL + HttpConfig.CHECK_EOS_ACCOUNT)
                .upRequestBody(body)
                .execute(new JsonCallBack<HttpData<BeanEos>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<BeanEos>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.checkEosAccountCallback(response.body().getData());
                        }
                    }
                });
    }

    public void createEosAccount(String account, String paswd) {

        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_EOS_ACCOUNT)
                .params("newAccount",account)
                .params("tradePwd",paswd,true)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.createEosAccountCallback(response.body().getData());
                        }
                    }
                });
    }


}
